#include "textbubble.h"

#include <gccore.h>
#include <wiiuse/wpad.h>

extern u8 bubble_png[];

extern u8 digital_ttf[];
extern u32 digital_ttf_size;

TextBubble::TextBubble()
{
	_textImage = new DrawableImage();
	_textImage2 = new DrawableImage();
	_textRender = new TextRender();

        _textRender->SetFont(digital_ttf, digital_ttf_size);

	Image* bubbleImage = new Image();
	if(bubbleImage->LoadImage(bubble_png, IMG_LOAD_TYPE_BUFFER) != IMG_LOAD_ERROR_NONE)exit(0);
  

	_textImage->CreateImage(640, 128);
	_textImage->SetFont(_textRender);
	_textImage->SetColor((GXColor){0,0,0,255});
	_textImage->SetSize(30);
	
	_textImage2->CreateImage(640, 128);
	_textImage2->SetFont(_textRender);
	_textImage2->SetColor((GXColor){0,0,0,255});
	_textImage2->SetSize(30);
	
	_bubble.SetImage(bubbleImage);
	_bubble.SetPosition(110,280);
}

TextBubble::~TextBubble()
{

}
		
void TextBubble::SetText(const char* txt, const char* txt2)
{
	_txt = (char*)txt;
	_txt2 = (char*)txt2;
}
	
void TextBubble::ClearText()
{
        _txt = NULL;
        _txt2 = NULL;
}
	
void TextBubble::Render()
{
	_bubble.Draw();

	if(_txt != NULL)
	{
		_textImage->RenderText(_txt);
		_textSprite.SetImage(_textImage->GetImage());
		_textSprite.SetPosition(140,300);
                _textSprite.Draw();
	}
	
	if(_txt2 != NULL)
	{
		_textImage2->RenderText(_txt2);
		_textSprite.SetImage(_textImage2->GetImage());
		_textSprite.SetPosition(140,340);
        _textSprite.Draw();
	}
}
		
void TextBubble::WaitForPress()
{
        while(1) {

                // Call WPAD_ScanPads each loop, this reads the latest controller states
                WPAD_ScanPads();

                // WPAD_ButtonsDown tells us which buttons were pressed in this loop
                // this is a "one shot" state which will not fire again until the button has been released
                u32 pressed = WPAD_ButtonsDown(0);

                // We return to the launcher application via exit
                if ( pressed & WPAD_BUTTON_A ) break;
        }
}
